package com.sample.db40;
import java.io.File;
import java.lang.reflect.*;
import com.db4o.*;
import com.sample.model.*;

// Version 1
public class BuildV1
{
    public static void main(String[] args)
        throws Exception
    {
        new File(".", "persons.data").delete();
        
        ObjectContainer db = null;
        try
        {
            db = Db4o.openFile("persons.data");

            Person brianG = new Person("Brian", "Goetz", 39);
            Person jason = new Person("Jason", "Hunter", 35);
            Person brianS = new Person("Brian", "Sletten", 38);
            Person david = new Person("David", "Geary", 55);
            Person glenn = new Person("Glenn", "Vanderberg", 40);
            Person neal = new Person("Neal", "Ford", 39);
            Person clinton = new Person("Clinton", "Begin", 19);
            
            db.set(brianG);
            db.set(jason);
            db.set(brianS);
            db.set(david);
            db.set(glenn);
            db.set(neal);
            db.set(clinton);

            db.commit();
            
            // Find all the Brians
            ObjectSet brians = db.get(new Person("Brian", null, 0));
            while (brians.hasNext())
                System.out.println(brians.next());            
        }
        finally
        {
            if (db != null)
                db.close(); 
        }
    }
}
